export function toTreeData (data, id, pid, name) {
  // 建立个树形结构,需要定义个最顶层的父节点，pid是0
  let parent = [];
  for (let i = 0; i < data.length; i++) {
    if (data[i][pid] !== 0) {
    } else {
      let obj = {
        label: data[i][name],
        id: data[i][id],
        children: []
      };
      parent.push(obj);//数组加数组值
    }
  }
  children(parent);

  // 调用子节点方法,参数为父节点的数组
  function children (parent) {
    if (data.length !== 0) {
      for (let i = 0; i < parent.length; i++) {
        for (let j = 0; j < data.length; j++) {
          if (parent[i].id == data[j][pid]) {
            let obj = {
              label: data[j][name],
              id: data[j][id],
              children: []
            };
            parent[i].children.push(obj);
          }
        }
        children(parent[i].children);
      }
    }
  }
  return parent;
}


function toTreeData (data) {
  // 建立个树形结构,需要定义个最顶层的父节点，pid是0
  let parent = [];
  for (let i = 0; i < data.length; i++) {
    if (data[i][pid] !== 0) {
    } else {
      let obj = {
        label: data[i][moduleName],
        id: data[i][id],
        children: []
      };
      parent.push(obj);//数组加数组值
    }
  }
  children(parent);

  // 调用子节点方法,参数为父节点的数组
  function children (parent) {
    if (data.length !== 0) {
      for (let i = 0; i < parent.length; i++) {
        for (let j = 0; j < data.length; j++) {
          if (parent[i].catalog == data[j][catalog]) {
            let obj = {
              label: data[j][name],
              id: data[j][id],
              children: []
            };
            parent[i].children.push(obj);
          }
        }
        children(parent[i].children);
      }
    }
  }
  return parent;
}